//
//  SellerMainViewController.m
//  SmartCoin
//
//  Created by apple on 2018/3/7.
//  Copyright © 2018年 Cynic. All rights reserved.
//

#import "SellerMainViewController.h"
#import "SellerOrderLsitViewController.h"
#import "SellerMineViewController.h"
#import "NewSellerOrderListViewController.h"
#import "ToolManagerViewController.h"
#import <ShareSDKExtension/ShareSDK+Extension.h>
@interface SellerMainViewController ()
@property (nonatomic ,retain)UIButton *currentTab;
@property (nonatomic ,retain)SellerOrderLsitViewController *SellerOrderListVC;
@property (nonatomic ,retain)NewSellerOrderListViewController *NewSellerOrderListVC;
@property (nonatomic ,retain)SellerMineViewController *SellerMineVC;
@property (nonatomic ,retain)ToolManagerViewController *ToolVC;
@end

@implementation SellerMainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self viewLoad];
}

-(void)viewLoad{
    [self tabLoad];
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    if ([self.childViewControllers[0] isEqual:_NewSellerOrderListVC]) {
        if (cx_hit == 812) {
            [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
        }
        else{
            [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
        }
    }
    else{
        [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
    }
}

-(void)tabLoad{
    NSArray *tabs = @[@[@"店铺",@"tab_home"],@[@"我的",@"tab_user"]];//底部导航栏
    if ([ShareSDK isClientInstalled:SSDKPlatformTypeWechat]) {
    tabs = @[@[@"店铺",@"tab_home"],@[@"工具",@"tab_home"],@[@"我的",@"tab_user"]];//新增工具模块
    }
    UIView *bottomview = [[UIView alloc] initWithFrame:CGRectMake(0,cx_hit - cxsingler.bottomdis - 50, cx_wid, 50)];
    
    UIView *topview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, cx_wid, 0.5)];
    topview.backgroundColor = [[UIColor lightGrayColor] colorWithAlphaComponent:0.3];
    [bottomview addSubview:topview];
    
    for (NSInteger index = 0; index < tabs.count; index ++) {
        UIButton *operation = [[UIButton alloc] initWithFrame:CGRectMake(cx_wid / tabs.count * index, 0, cx_wid / tabs.count, 50)];
        operation.titleLabel.font = [UIFont systemFontOfSize:10];
        [operation setImage:[UIImage imageNamed:tabs[index][1]] forState:UIControlStateNormal];
        [operation setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@_color",tabs[index][1]]] forState:UIControlStateSelected];
        [operation setTitle:tabs[index][0] forState:UIControlStateNormal];
        [operation setTitleColor:[CXSinglerModel colorWithHex:@"fb5448" alpha:1] forState:UIControlStateSelected];
        [operation setTitleColor:[CXSinglerModel colorWithHex:@"cdcdcd" alpha:1] forState:UIControlStateNormal];
        [bottomview addSubview:operation];
        [operation setTitleEdgeInsets:UIEdgeInsetsMake(25, 0, 0, 20)];
        [operation setImageEdgeInsets:UIEdgeInsetsMake(0, 21, 15, 0)];
        if (index == 0) {
            operation.selected = YES;
            _currentTab = operation;
        }
        WEAKSELF;
        __weak typeof(operation) weakBtn = operation;
        [operation cx_eventsBlockHandler:^{
            [self.view endEditing:YES];
            if ([weakBtn isEqual:weakSelf.currentTab]) {
                
            }
            else{
                weakSelf.currentTab.selected = NO;
                weakBtn.selected = YES;
                weakSelf.currentTab = weakBtn;
                NSInteger seg = 1;
                if ([weakBtn.titleLabel.text isEqual:@"店铺"]) {
                    seg = 0;
                }
                else if ([weakBtn.titleLabel.text isEqual:@"工具"]){
                    seg = 2;
                }
                [self loadpart:seg];
            }
        } forControlEvents:UIControlEventTouchUpInside];
    }
    [self.view addSubview:bottomview];
    
    
    [self loadpart:0];
}

-(void)loadpart:(NSInteger)partnum{
    switch (partnum) {
        case 0:
        {
            if (!_NewSellerOrderListVC) {
                _NewSellerOrderListVC = [[NewSellerOrderListViewController alloc] initInChildWithFrame:CGRectMake(0, 0, cx_wid, cx_hit - cxsingler.bottomdis - 50)];
            }
            if (self.childViewControllers.count > 0) {
                [[(BaseViewController *)(self.childViewControllers[0]) view] removeFromSuperview];
                [(BaseViewController *)(self.childViewControllers[0]) removeFromParentViewController];
            }
            [self addChildViewController:_NewSellerOrderListVC];
//            [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
            [self.view addSubview:_NewSellerOrderListVC.view];
//            if (!_SellerOrderListVC) {
//                _SellerOrderListVC = [[SellerOrderLsitViewController alloc] initInChildWithFrame:CGRectMake(0, 0, cx_wid, cx_hit - cxsingler.bottomdis - 50)];
//            }
//            if (self.childViewControllers.count > 0) {
//                [_SellerMineVC removeFromParentViewController];
//                [_SellerMineVC.view removeFromSuperview];
//            }
//            [self addChildViewController:_SellerOrderListVC];
//            [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
//            [self.view addSubview:_SellerOrderListVC.view];
        }
            break;
        case 1:
        {
            if (!_SellerMineVC) {
                _SellerMineVC = [[SellerMineViewController alloc] initWithSeller];
            }
            if (self.childViewControllers.count > 0) {
                [[(BaseViewController *)(self.childViewControllers[0]) view] removeFromSuperview];
                [(BaseViewController *)(self.childViewControllers[0]) removeFromParentViewController];
            }
            [self addChildViewController:_SellerMineVC];
//            [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
            [self.view addSubview:_SellerMineVC.view];
            
        }
            break;
        case 2:
        {
            
            if (!_ToolVC) {
                _ToolVC = [[ToolManagerViewController alloc] init];
            }
            if (self.childViewControllers.count > 0) {
                [[(BaseViewController *)(self.childViewControllers[0]) view] removeFromSuperview];
                [(BaseViewController *)(self.childViewControllers[0]) removeFromParentViewController];
                
            }
            [self addChildViewController:_ToolVC];
//            [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
            [self.view addSubview:_ToolVC.view];
            
        }
            break;
        default:
            break;
    }
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
}
/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
